const http = require("http");
const path = require("path");
const fs = require("fs");
const url = require("url");

const cheerio = require("cheerio");
var filePath = path.join(__dirname, "/movie.html");
var content = fs.readFileSync(filePath);
content = content.toString("utf-8");

var $ = cheerio.load(content);
var arr = [];

$(".channel-detail.movie-item-title a").each((i, el) => {
    var obj = {};
    obj.movieId = $(el).attr("data-val").toString().split(":")[1].slice(0, -1);
    obj.movieName = $(el).text();
    arr.push(obj);
});
$(".channel-detail.channel-detail-orange").each((i, el) => {
    arr[i]["movieOrange"] = $(el).text();
});

var rurl = "http://localhost:8080";
var options = url.parse(rurl);

options.method = "POST";

var user = arr;
var useStr = JSON.stringify(user);
var request = http.request(options, (res) => {});
request.write(useStr);
request.end();
